<template>
  <div class="search-result">
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了"
      @load="onLoad">
      <ArticleItem v-for="(item,index) in list" :key="index" :article="item">
      </ArticleItem>
    </van-list>
  </div>
</template>

<script>
import ArticleItem from '@/components/article-item'
import { getSearchResult } from '@/api/user.js'
export default {
  name: 'SearchResult',
  components: { ArticleItem },
  props: {
    searchText: {
      type: String,
      require: true
    }
  },
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 0
    }
  },
  computed: {},
  watch: {},
  created () { },
  mounted () { },
  methods: {
    async onLoad () {
      this.page++
      const { data: { data: { results: [...res] } } } = await getSearchResult({ q: this.searchText, page: this.page })
      console.log(res)
      this.list.push(...res)
      if (res.length === 0) {
        this.finished = true
      }
      this.loading = false
    }
  }
}
</script>

<style scoped lang="less">
</style>
